Skip to content

Conversation

@InsanityGod
Copy link
Contributor

@InsanityGod InsanityGod commented Oct 10, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Corrected text replacement behavior when typing over a selection, ensuring the correct range is replaced regardless of selection direction (left-to-right or right-to-left).
    • Improves consistency when inserting or pasting text over highlighted content, preventing unexpected characters from remaining or being removed.

@coderabbitai
Copy link

coderabbitai bot commented Oct 10, 2025

Walkthrough

InsertTextAtCursor now computes replacement boundaries using TrueSelectionStartWithoutLineBreaks and TrueSelectionEndWithoutLineBreaks when a selection exists, ensuring correct start/end positions regardless of selection direction. No other logic in the method changed.

Changes

Cohort / File(s) Summary
Text insertion selection handling
VTMLEditor/GuiElements/Vanilla/GuiElementEditableTextBase.cs
Replace SelectionStartWithoutLineBreaks/SelectionEndWithoutLineBreaks with TrueSelectionStartWithoutLineBreaks/TrueSelectionEndWithoutLineBreaks for replacement range in InsertTextAtCursor; remaining logic unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant E as EditableTextBase
  participant S as Selection State
  participant D as Document Buffer

  U->>E: InsertTextAtCursor(text)
  E->>S: Check selection range
  alt Selection exists
    S-->>E: TrueSelectionStart/End (no line breaks)
    note over E: Use TrueSelection* to compute replacement
    E->>D: Replace [start:end] with text
  else No selection
    E->>D: Insert text at caret position
  end
  E->>S: Update caret and selection
  E-->>U: Return
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibble on code like clover at dawn,
Flip-flopped selections now tidy and drawn.
True starts, true ends, no lines astray—
Cursor hops lightly, on its way.
In fields of text, I bop and weave,
A happy hare with tricks up sleeve. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title directly names the affected method and succinctly describes the bug fix—switching to TrueSelection to handle inverse selections—which matches the core change implemented in the pull request.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a726e9 and 859acc2.

📒 Files selected for processing (1)
  • VTMLEditor/GuiElements/Vanilla/GuiElementEditableTextBase.cs (1 hunks)
🔇 Additional comments (1)
VTMLEditor/GuiElements/Vanilla/GuiElementEditableTextBase.cs (1)

456-457: LGTM! Correct fix for inverse selection handling.

The change properly normalizes selection boundaries using TrueSelectionStartWithoutLineBreaks and TrueSelectionEndWithoutLineBreaks, ensuring that start is always ≤ end regardless of selection direction. This prevents incorrect text replacement when users select text backwards (right-to-left or bottom-to-top). The fix is consistent with other methods in the codebase (DeleteSelection at lines 477-478, GetSelectedText at line 268).


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant